package advanced.concurrent;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class CopyOnWriteArrayList_L {
    private static Object[] arr = new Object[323];

    public static void main(String[] args) {
        Object[] arr = {3, 4, 5, 3};
        Object[] copy = Arrays.copyOf(arr, arr.length + 1);
        copy[arr.length] = 1000;
        for (Object o : copy) {
            System.out.println(o);
        }
        CopyOnWriteArrayList list = new CopyOnWriteArrayList(List.of(1, 2, 3, 4, 45));
        list.add(23);


        ReentrantLock lock = new ReentrantLock();
        lock.lock();
        try {
            Condition condition = lock.newCondition();
            /**
             * 唤醒一个正在等待的线程。
             * 如果有任何线程在此条件下等待，则选择一个线程进行唤醒。然后，该线程必须在从wait返回之前重新获取锁。
             */
            condition.signal();
        } finally {
            lock.unlock();
        }

    }

    public <E extends Object> E getEle(int index) {
        return (E) arr[index];
    }
}
